﻿using System;
using System.Collections.Generic;
using System.Text;
using AgencyManagerSystem.Model;
using AgencyManagerSystem.Common;
using Dapper;
using System.Linq;

namespace AgencyManagerSystem.DataFetcher
{
    public class NoticFetcher : BaseFetcher<NoticModel>
    {
        public NoticFetcher() : base()
        {
            
        }
        public IList<NoticModel> ListByReceiver(int receiver ,int pos , int size ,out int count)
        {
            string sqlstr = String.Format("SELECT * FROM SYS_NOTIC WHERE RECEIVER = 0 OR RECEIVER = {0} ORDER BY RECEIVER,AUTOID DESC LIMIT {1},{2}", receiver, pos, size);
            string sqlstrCnt = String.Format("SELECT COUNT(*) FROM SYS_NOTIC WHERE RECEIVER = 0 OR RECEIVER = {0} ORDER BY RECEIVER,AUTOID DESC LIMIT {1},{2}", receiver, pos, size);
            count = 0;
            IList<NoticModel> result = null;
            LogHelper.Debug(this.GetType().Name, sqlstr);
            try
            {
                result = DBHelper.GetTran().Query<NoticModel>(sqlstr).AsList();
                count = DBHelper.GetTran().Query<Int32>(sqlstrCnt).AsList().First();
            }
            catch (Exception ex)
            {
                LogHelper.Err(this.GetType().Name, ex.Message + "-" + ex.StackTrace);
            }
            return result;
        }
    }
}
